package hu.debrecen.adastra.card.web.domain;

import hu.debrecen.adastra.card.service.domain.Card;
import hu.debrecen.adastra.card.service.impl.ZsirozasCardGame.Action;

import java.util.List;

import org.codehaus.jackson.annotate.JsonProperty;

import com.google.common.base.Function;
import com.google.common.collect.Lists;

public class ZsirGameStateVO extends AbstractGameStateVO {

	private static final long serialVersionUID = 1L;

	private boolean caller;

	private int deckSize;

	private int opponentHandCount;

	private List<Card> table;

	private List<HandCardVO> hand;

	private Boolean possiblePass;

	private boolean timeExpWarning;

	public ZsirGameStateVO() {
		super();
	}

	public ZsirGameStateVO(final int deckSize, final boolean caller, final boolean possiblePass, final boolean timeExpWarning, final List<Card> table, final List<HandCardVO> hand, final Action... actions) {
		this.deckSize = deckSize;
		this.caller = caller;
		this.possiblePass = possiblePass;
		this.timeExpWarning = timeExpWarning;
		this.table = table;
		this.hand = hand;
		this.setActions(Lists.transform(Lists.newArrayList(actions), new Function<Action, String>() {
			@Override
			public String apply(final Action action) {
				return action.name();
			}
		}));
	}

	public ZsirGameStateVO(final int deckSize, final boolean caller, final boolean possiblePass, final boolean timeExpWarning, final List<Card> table, final List<HandCardVO> hand,
			final List<Card> opponentHand, final Action... actions) {
		this(deckSize, caller, possiblePass, timeExpWarning, table, hand, actions);
		this.setOpponentHandCount(opponentHand.size());
	}

	@JsonProperty("dS")
	public int getDeckSize() {
		return this.deckSize;
	}

	public void setDeckSize(final int deckSize) {
		this.deckSize = deckSize;
	}

	@Override
	@JsonProperty("c")
	public boolean getCaller() {
		return this.caller;
	}

	public void setCaller(final boolean caller) {
		this.caller = caller;
	}

	@Override
	@JsonProperty("t")
	public List<Card> getTable() {
		return this.table;
	}

	public void setTable(final List<Card> table) {
		this.table = table;
	}

	@Override
	@JsonProperty("h")
	public List<HandCardVO> getHand() {
		return this.hand;
	}

	public void setHand(final List<HandCardVO> hand) {
		this.hand = hand;
	}

	@Override
	@JsonProperty("f")
	public Boolean isFinished() {
		return this.table.isEmpty() && this.hand.isEmpty() && (this.opponentHandCount == 0);
	}

	@JsonProperty("p")
	public Boolean isPossiblePass() {
		return this.possiblePass;
	}

	@JsonProperty("oHC")
	public int getOpponentHandCount() {
		return this.opponentHandCount;
	}

	public void setOpponentHandCount(final int opponentHandCount) {
		this.opponentHandCount = opponentHandCount;
	}

	@Override
	@JsonProperty("a")
	public List<String> getActions() {
		return super.getActions();
	}

	@JsonProperty("tEW")
	public boolean isTimeExpWarning() {
		return this.timeExpWarning;
	}

}
